package com.fanco.learn_datastruct_leetcode.jvm;

import java.lang.ref.WeakReference;

/**
 * @author qiaowang 2021/8/27
 * 描述
 */
public class WeakReferenceDemo {
    public static void main(String[] args) {
        Object o1 = new Object();
        WeakReference<Object> weakReference = new WeakReference<Object>(o1);
        System.out.println(o1);

        System.out.println(weakReference.get());
        // 当弱应用 对应的引用被释放
        o1 = null;

        System.gc();
        // gc后弱引用被回收
        System.out.println(o1);
        System.out.println(weakReference.get());

    }
}
